/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Test.java
 *
 * Created on Mar 22, 2009, 11:28:10 AM
 */

package client;

import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractListModel;
import javax.swing.ListModel;



/**
 *
 * @author scriptoff
 */
public class InitTabCanal extends javax.swing.JPanel {
    private String nomCanal ;
    private Client cl ;
    private Menu_ImSSL_GUI gui ;
    /** Creates new form Test */
    public InitTabCanal( String nomCanal , final Vector listeUtilisateurs , Client cl , Menu_ImSSL_GUI gui ) {
        this.gui = gui ;
        this.cl = cl ;
        this.nomCanal = nomCanal ;
        initComponents();
        jList1.setModel(new javax.swing.AbstractListModel() {
            Vector strings = listeUtilisateurs ;
            public int getSize() { return strings.size(); }
            public Object getElementAt(int i) { return strings.get(i); }
        });
    }

    String getNomCanal() {
        return nomCanal ;
    }

    void nouveauMessage( String pseudo , String msg) {
        String text = jTextArea1.getText();
        jTextArea1.setText(text+pseudo+'>'+msg+"\n");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jTextField1 = new javax.swing.JTextField();
        bouton_envoyer = new javax.swing.JButton();
        bouton_bannir = new javax.swing.JButton();
        bouton_dialoguer = new javax.swing.JButton();
        bouton_op = new javax.swing.JButton();
        bouton_deop = new javax.swing.JButton();
        bouton_expulser = new javax.swing.JButton();
        bouton_deconnecter = new javax.swing.JButton();
        bouton_supprimer = new javax.swing.JButton();
        bouton_bannir1 = new javax.swing.JButton();

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField1KeyPressed(evt);
            }
        });

        bouton_envoyer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/tick.png"))); // NOI18N
        bouton_envoyer.setText("Envoyer");
        bouton_envoyer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_envoyerActionPerformed(evt);
            }
        });

        bouton_bannir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/flag_red.png"))); // NOI18N
        bouton_bannir.setText("Bannir");
        bouton_bannir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_bannirActionPerformed(evt);
            }
        });

        bouton_dialoguer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/arrow_right.png"))); // NOI18N
        bouton_dialoguer.setText("Dialoguer");
        bouton_dialoguer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_dialoguerActionPerformed(evt);
            }
        });

        bouton_op.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/plus_icon.gif"))); // NOI18N
        bouton_op.setText("Mettre operateur");
        bouton_op.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_opActionPerformed(evt);
            }
        });

        bouton_deop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/minus_icon.png"))); // NOI18N
        bouton_deop.setText("Enlever operateur");
        bouton_deop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_deopActionPerformed(evt);
            }
        });

        bouton_expulser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/nettoyer.png"))); // NOI18N
        bouton_expulser.setText("Expulser");
        bouton_expulser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_expulserActionPerformed(evt);
            }
        });

        bouton_deconnecter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/quitter.png"))); // NOI18N
        bouton_deconnecter.setText("Quitter");
        bouton_deconnecter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_deconnecterActionPerformed(evt);
            }
        });

        bouton_supprimer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/cancel.png"))); // NOI18N
        bouton_supprimer.setText("Supprimer");
        bouton_supprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_supprimerActionPerformed(evt);
            }
        });

        bouton_bannir1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/tick.png"))); // NOI18N
        bouton_bannir1.setText("Débannir");
        bouton_bannir1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_deBannirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jTextField1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bouton_envoyer, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 857, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bouton_supprimer, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                            .addComponent(bouton_expulser, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                            .addComponent(bouton_op, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                            .addComponent(bouton_bannir, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(bouton_dialoguer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bouton_bannir1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bouton_deconnecter, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bouton_deop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bouton_deconnecter)
                            .addComponent(bouton_supprimer))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bouton_expulser)
                            .addComponent(bouton_dialoguer))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bouton_bannir)
                            .addComponent(bouton_bannir1)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 577, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(bouton_op)
                        .addComponent(bouton_deop)
                        .addComponent(bouton_envoyer))
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bouton_envoyerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_envoyerActionPerformed
        String msg =  jTextField1.getText();
        jTextField1.setText("");
        if ( msg == null )
            return ;
        else
            cl.envoyerMessage(nomCanal, msg);
   
}//GEN-LAST:event_bouton_envoyerActionPerformed

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER)
            bouton_envoyerActionPerformed(null);
    }//GEN-LAST:event_jTextField1KeyPressed

    private void bouton_bannirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_bannirActionPerformed
        Object  []objTab =   jList1.getSelectedValues();
         if (objTab.length != 0){
            for ( Object obj : objTab ){
                cl.bannir(nomCanal, obj.toString());
            }
         }
}//GEN-LAST:event_bouton_bannirActionPerformed

    private void bouton_deconnecterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_deconnecterActionPerformed
       cl.quitterCanal(nomCanal);
       gui.detruireCanal(nomCanal);
    }//GEN-LAST:event_bouton_deconnecterActionPerformed

    private void bouton_expulserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_expulserActionPerformed
        Object  []objTab =   jList1.getSelectedValues();
         if (objTab.length != 0){
            for ( Object obj : objTab ){
                cl.expulser(nomCanal,obj.toString());
            }
         }
    }//GEN-LAST:event_bouton_expulserActionPerformed

    private void bouton_dialoguerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_dialoguerActionPerformed
          Object  []objTab =   jList1.getSelectedValues();
         if (objTab.length != 0){
            for ( Object obj : objTab ){
                cl.dialoguer(obj.toString());
            }
         }
}//GEN-LAST:event_bouton_dialoguerActionPerformed

    private void bouton_opActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_opActionPerformed
         Object  []objTab =   jList1.getSelectedValues();
         if (objTab.length != 0){
            for ( Object obj : objTab ){
                cl.op(nomCanal,obj.toString());
            }
         }
    }//GEN-LAST:event_bouton_opActionPerformed

    private void bouton_deopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_deopActionPerformed
         Object  []objTab =   jList1.getSelectedValues();
         if (objTab.length != 0){
            for ( Object obj : objTab ){
                cl.deOp(nomCanal,obj.toString());
            }
         }
    }//GEN-LAST:event_bouton_deopActionPerformed

    private void bouton_supprimerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_supprimerActionPerformed
        cl.supprimerCanal(nomCanal);
    }//GEN-LAST:event_bouton_supprimerActionPerformed

    private void bouton_deBannirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_deBannirActionPerformed
        // TODO add your handling code here:
        String reponse =  javax.swing.JOptionPane.showInputDialog("Pseudo");
        cl.deBannir( nomCanal , reponse);
}//GEN-LAST:event_bouton_deBannirActionPerformed

    public void changerModel ( final Vector listeUtilisateurs ) {
        jList1.setModel(new javax.swing.AbstractListModel() {
            Vector strings = listeUtilisateurs ;
            public int getSize() { return strings.size(); }
            public Object getElementAt(int i) { return strings.get(i); }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bouton_bannir;
    private javax.swing.JButton bouton_bannir1;
    private javax.swing.JButton bouton_deconnecter;
    private javax.swing.JButton bouton_deop;
    private javax.swing.JButton bouton_dialoguer;
    private javax.swing.JButton bouton_envoyer;
    private javax.swing.JButton bouton_expulser;
    private javax.swing.JButton bouton_op;
    private javax.swing.JButton bouton_supprimer;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
